package com.biz.service.api;

import com.biz.model.Pmodel.api.OrderMain90;
import com.biz.model.Pmodel.api.Record90Detail;
import com.biz.model.Pmodel.api.Shop;
import com.alibaba.fastjson.JSON;
import com.biz.conf.Global;
import com.biz.model.Hmodel.TorderMain;
import com.biz.model.Pmodel.api.*;
import com.biz.service.base.BaseServiceI;
import com.biz.service.base.BaseServiceImpl;
import com.framework.dao.mdao.DaoSupport;
import com.framework.model.Pager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by lzq on 2017/2/4.
 */

@Service("orderMainService")
public class OrderMainServiceImpl extends BaseServiceImpl implements OrderMainServiceI {
    @Resource(name = "daoSupport")
    private DaoSupport dao;

    /**
     * 联盟商户发劵记录
     */
    public List<Record90Detail> phone_90Record(Map<String, Object> hashMap) throws Exception
    {
        return (List<Record90Detail>)dao.findForList("OrderMainDao.phone_90Record",hashMap);
    }

    public int phone_90RecordCount(Map<String, Object> hashMap) throws Exception
    {
        return (int) dao.findForObject("OrderMainDao.phone_90RecordCount",hashMap);
    }


    public OrderMain90 getOrderMain90ByCode(String code) throws Exception
    {
        return (OrderMain90) dao.findForObject("OrderMainDao.getOrderMain90ByCode", code);
    }

    public Shop getShopBySid(String sid) throws Exception {
        return (Shop) dao.findForObject("OrderMainDao.getShopBySid", sid);
    }

    public String getSysUserIdByOpenId(String openid)throws Exception
    {
        return (String) dao.findForObject("OrderMainDao.getSysUserIdByOpenId", openid);
    }

    public Double getBalanceByOrderNum(String orderNum)throws Exception
    {
        Object total = dao.findForObject("OrderMainDao.getBalanceByOrderNum", orderNum);
        if(total==null){
            return 0.0;
        }else
        {
            return Double.parseDouble(total.toString());
        }
    }

    /**
     * 更新某个字段
     */
    public void updateWhereOrderMain90(Map<String,Object> params) throws Exception
    {
        dao.update("OrderMainDao.updateWhereOrderMain90", params);
    }

    @Override
    public List<OrderMainUnion> collectRecordForClerk(Map<String, Object> pd) throws Exception {
        if("1".equals(pd.get("type")+""))
        {
            pd.put("shop_id", pd.get("code")+"");
            return (List<OrderMainUnion>) dao.findForList("OrderMainUnionDao.collectRecord",pd);
        }else{
            return (List<OrderMainUnion>) dao.findForList("OrderMainUnionDao.collectRecordForClerk",pd);
        }
    }

    @Override
    public int checkNum(Map<String, Object> pd) throws Exception {
      return (int) dao.findForObject("OrderMainDao.checkNum",pd);
    }

    @Override
    public double checkMoneyNum(Map<String, Object> pd) throws Exception {
        return (double) dao.findForObject("OrderMainDao.checkMoneyNum",pd);
    }

    @Override
    public double collectMoneyNum(Map<String, Object> pd) throws Exception {
        return (double) dao.findForObject("OrderMainDao.collectMoneyNum",pd);
    }

    @Override
    public int collectNum(Map<String, Object> pd) throws Exception {
        return (int) dao.findForObject("OrderMainDao.collectNum",pd);
    }

    @Override
    public int getBalance_90(Map<String, Object> pd) throws Exception {
        return (int) dao.findForObject("OrderMainDao.getBalance_90",pd);
    }

    @Override
    public Pager<DetailVoucher> queryDetailVoucherList(Pager<DetailVoucher> pager) throws Exception{
        return dao.findForPager1("OrderMainDao.queryDetailVoucherList","OrderMainDao.queryDetailVoucherCount",pager);
    }
}
